﻿/*
Copyright (C) 2008 raohmaru <http://www.raohmaru.com>

This file is part of Raohmaru AS3 Framework.

Raohmaru AS3 Framework is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Raohmaru AS3 Framework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with Raohmaru AS3 Framework.  If not, see <http://www.gnu.org/licenses/>.
*/

package jp.raohmaru.utils
{
import flash.net.navigateToURL;
import flash.net.URLRequest;

/**
 * Conjunto de utilidades para la navegación web y los métodos HTTP.
 * @author raohmaru
 * @version 1.0
 */
public class WebUtil
{
	/**
	* Implementa el método getURL previo a AS3.
	* @param url Dirección URL
	* @param window Ventana de destino
	* @author Trevor McCauley (http://www.senocular.com/)
	*/
    public static function getURL(url:String, window:String = "_self") : void
    {
        var req:URLRequest = new URLRequest(url);
        
        try
        {
            navigateToURL(req, window);
        }
        catch (e:Error)
        {
            trace("Navigate to URL failed ", e.message);
        }
    }
    
	/**
	* Devuelve una variable get con un valor aleatorio para evitar que se caché una URL.
	* @param delim Caracter separador que irá delante de la cadena resultante
	* @return String
	* @example <listing version="3.0">Web.noCache("&");      // "&nch=485548752659"</listing>
	*/
    public static function noCache(delim : String = "?") : String
    {
    	return delim + "nch=" + noCacheNum();
    }
    
	/**
	* Devuelve un valor aleatorio que ha de añadirse al final de una petición URL para evitar que se caché.
	* @return uint
	*/
    public static function noCacheNum() : uint
    {
    	return Math.random()*1000000000000;
    }
}
}
